import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import load
from sklearn.cluster import KMeans

allJingA=[]
allWeiA=[]
allJiageA=[]
allJingB=[]
allWeiB=[]
allJiageB=[]

for i in range(1,836):
    jingdu=float(load.getCellT1(i,load.jingdu))
    weidu=float(load.getCellT1(i,load.weidu))
    wancheng=int(load.getCellT1(i,load.wancheng))
    if wancheng==1:
        allJingA.append(jingdu)
        allWeiA.append(weidu)
        allJiageA.append(float(load.getCellT1(i,load.jiage)))
    else:
        allJingB.append(jingdu)
        allWeiB.append(weidu)
        allJiageB.append(float(load.getCellT1(i, load.jiage)))

if __name__=='__main__':
    allPos = [(allJingA[i], allWeiA[i]) for i in range(len(allJingA))]
    estimator = KMeans(n_clusters=3) # 构造聚类器
    estimator.fit(allPos) # 聚类
    print(estimator.cluster_centers_)

    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter(allJingA, allWeiA, allJiageA,c='blue')
    ax.scatter(allJingB, allWeiB, allJiageB, c='green')
    plt.show()